package cn.momoky.ccool.utils;

import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class Result<T> {

    private Integer code;
    private T data;
    private String message;


    public static <T> Result<T> ok() {
        return new Result<T>()
                .setCode(ResultStatus.SUCCESS.getCode())
                .setMessage(ResultStatus.SUCCESS.getMsg());
    }

    public static <T> Result<T> ok(T data) {
        return new Result<T>()
                .setCode(ResultStatus.SUCCESS.getCode())
                .setMessage(ResultStatus.SUCCESS.getMsg())
                .setData(data);
    }

    public static <T> Result<T> error() {
        return new Result<T>()
                .setCode(ResultStatus.INTERNAL_SERVER_ERROR.getCode())
                .setMessage(ResultStatus.INTERNAL_SERVER_ERROR.getMsg());
    }

    public static <T> Result<T> error(String message) {
        return new Result<T>()
                .setCode(ResultStatus.INTERNAL_SERVER_ERROR.getCode())
                .setMessage(message);
    }

    public static <T> Result<T> error(Integer code, String message) {
        return new Result<T>()
                .setCode(code)
                .setMessage(message);
    }

}
